<template>
  <div class="content-wrapper">
    <!-- <div class="content-header"></div>
           <div class="title">
      <div>我参与的</div>
    </div>
       <el-divider></el-divider> -->
    <div class="content-container">
      <el-form :inline="true" :model="listQuery" class="filter-container">
        <el-form-item label="流程类型">
          <el-select v-model="listQuery.flowType" size="mini">
            <el-option
              v-for="item in flowTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="文件编号" min-width="220">
          <el-input v-model="listQuery.documentCode" type="text" size="mini" />
        </el-form-item>
        <el-form-item label="处理时间范围">
          <el-date-picker
            v-model="listQuery.startHandleTime"
            type="datetime"
            placeholder="选择开始时间"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
          <span> - </span>
          <el-date-picker
            v-model="listQuery.endHandleTime"
            type="datetime"
            placeholder="选择截止时间"
            size="mini"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            class="filter-item"
            size="small"
            round
            type="primary"
            icon="el-icon-search"
            @click="handleFilter"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
      <div>
        <el-table
          v-if="list"
          v-loading="listLoading"
          height="500"
          :data="list"
          highlight-current-row
        >
          <el-table-column
            label="流程类型"
            prop="flowTypeName"
            width="120px"
            sortable
          />
          <el-table-column
            label="文件编号"
            prop="documentCode"
            width="200px"
            sortable
          />
          <el-table-column
            label="文件名称"
            prop="documentName"
            min-width="180px"
            show-overflow-tooltip
          />
          <el-table-column
            label="紧急程度"
            prop="urgentName"
            width="100px"
            align="center"
          />
          <el-table-column
            label="申请原因"
            prop="reason"
            show-overflow-tooltip
            min-width="200px"
            align="left"
          />
          <el-table-column label="当前阶段" prop="phaseName" width="100px" />
          <el-table-column
            label="发起时间"
            prop="accessTimeString"
            width="150px"
          />
          <el-table-column
            label="操作"
            align="center"
            width="60px"
            fixed="right"
          >
            <template slot-scope="{ row }">
              <el-dropdown trigger="click" class="filter-item">
                <el-button type="text"><i class="el-icon-more" /></el-button>
                <el-dropdown-menu slot="dropdown" class="user-dropdown">
                  <el-dropdown-item
                    @click.native.prevent="preview(row)"
                  >查看</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page-number.sync="listQuery.pageNumber"
          :page-size.sync="listQuery.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import {
  pageParticipantDocumentFlow,
  getPhaseSmall
} from '@/api/xd/documentFlow'
import { listDictTreeItem } from '@/api/base/dict'
import '@/styles/flow.scss'

export default {
  components: { Pagination },
  data() {
    return {
      flowTypeOptions: [],
      listQuery: {
        pageNumber: 1,
        pageIndex: 0,
        pageSize: 10,
        flowType: null,
        documentCode: null,
        startHandleTime: null,
        endHandleTime: null
      },
      list: null,
      total: 0,
      listLoading: true
    }
  },
  mounted() {
    listDictTreeItem({ dictGroupCode: 'flow_type' }).then((response) => {
      const array = response.data || []
      array.splice(0, 0, { label: '全部', value: null })
      this.flowTypeOptions = array
    })
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      this.listQuery.pageIndex = this.listQuery.pageNumber - 1
      pageParticipantDocumentFlow(this.listQuery)
        .then((response) => {
          this.list = response.data.rows
          this.total = response.data.total
        })
        .finally(() => {
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.pageNumber = 1
      this.getList()
    },
    preview(row) {
      this.$router.push({
        path: '/flow/participant',
        query: {
          phase: getPhaseSmall(row.phase),
          row: JSON.stringify(row)
        }
      })
    }
  }
}
</script>
